<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box" style="padding-left:0px;">
                <div class="panel-search">
                    <el-input v-model="search.teacherName" placeholder="教练" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding" style="min-height:600px;">
                <scDialogTable v-if="search.agentId" ref="table" :apiObj="$API.agent.teacher.list" remoteSort :params="search" :exportData="exportData" :formatExportData="formatExportData" :height="600">
                    <el-table-column label="教练">
                        <template #default="scope">
                            {{scope.row.teacher && scope.row.teacher.name || '暂无'}}
                        </template>
                    </el-table-column>
                    <el-table-column label="开通时间" prop="createdAt" align="center" width="150"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="150">
                        <template #default="scope">
                            <el-button type="text" size="small" @click="table_show(scope.row)">查看</el-button>
                        </template>
                    </el-table-column>
                </scDialogTable>
            </el-main>
        </el-container>
    </el-container>

    <detail v-if="dialog.detail" ref="detailDialog"></detail>

</template>

<script>
import detail from '../../teacher/detail.vue'
export default {
    components: {
        detail
    },
    props: {
        agent: { type: Object, default: () => {} },
    },
    data() {
        return {
            loading: false,
            visible: false,
            dialog: {
                detail: false,
            },
            search: {
                agentId: ''
            }
        }
    },
    created() {
        if (this.agent) {
            this.search.agentId = this.agent.id
        }
    },
    mounted() {
    },
    methods: {
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //查看
        async table_show(row) {
            this.dialog.detail = true
            let teacherId = row.teacher && row.teacher.id || 0
            this.$nextTick(() => {
                this.$refs.detailDialog.open(teacherId, 'first')
            })
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
/* dialog内上边距设置 */
.position {
    display: flex;
    align-items: center;
}
.position-item {
    margin-right: 5px;
}
.position-item:last-child {
    margin-right: 0;
}
/* dialog内上边距设置 END */
.stemClass img{
    max-width: 100%;
    width: 200px;
    height: 100px;
}
</style>
